/****************************************************************
*****************************************************************/

*by Xiaodong Fan, fanxiaodong@gmail.com

#delimit ;

cap log close;
clear all;
drop _all;
set more 1;
pause on;

log using log_plot_FS.log, replace;

global gpicsdir "pics_FS";
global gdtadir ".";

do do_globals.do;

local lvxlabel0 "xlabel(18 22 30(10)80,grid)";
local lvxlabel1 "xlabel(22 26 30(10)80,grid)";
local lvcond "if t>10 & t<=80";

** Family status distribution ** ;
use ../../../Sipp_data/Fan/moments/dta_sipp_cleaned.dta, clear;
keep if col == 0 | col == 1;
gen byte Mt = 0 if spspres==0;
replace Mt = 1 if spspres==1 & spswk == 0;
replace Mt = 2 if spspres==1 & spswk == 1;
drop if missing(Mt);
gen sng=(Mt==0);
gen spnw=(Mt==1);
gen spw=(Mt==2);
collapse (mean) sng spnw spw, by(col age);
sort col age;
ren age t;
foreach icol in 0 1 {;
   line sng spnw spw t `lvcond' & col==`icol', graphregion(color(white)) 
        lpattern("l" "_" "-")  xtitle("Age") `lvxlabel`icol''
        ytitle("Distribution") yscale(range(0 1)) ylabel(0(0.2)1)
        legend(pos(1) ring(0) col(1) order(1 "Single" 2 "Spouse not working" 3 "Spouse working"));
   graph export ${gpicsdir}/eps_col`icol'_FSdis_data.eps,replace;
};

use dta_MSM_ProfilesMoments.dta if ihet==0, clear;
sort t;
gen col = 0;
foreach icol in 0  {;
   line single mrdspnw mrdspw t `lvcond' & col==`icol', graphregion(color(white)) 
        lpattern("l" "_" "-")  xtitle("Age") `lvxlabel`icol''
        ytitle("Distribution") yscale(range(0 1)) ylabel(0(0.2)1)
        legend(pos(1) ring(0) col(1) order(1 "Single" 2 "Spouse not working" 3 "Spouse working"));
   graph export ${gpicsdir}/eps_col`icol'_FSdis_sim.eps,replace;
};

*cap log close;
*stop;

***********************************************;
**  Family status transition;
************************************************;

infile col t Mt Mt0 Mt1 Mt2 using ../../bpfcodes_com/data/raw_sipp_Mt.raw, clear;
sort col t;

foreach icol in 0 1 {;
    foreach iMt in 0 1 2 {;
       line Mt0 Mt1 Mt2 t `lvcond' & col==`icol' & Mt==`iMt', graphregion(color(white)) 
            lpattern("l" "_" "-")  xtitle("Age") `lvxlabel`icol''
            ytitle("Probability") yscale(range(0 1)) ylabel(0(0.2)1)
            legend(pos(3) ring(0) col(1) order(1 "Single" 2 "Spouse not working" 3 "Spouse working"));
       graph export ${gpicsdir}/eps_col`icol'_FS`iMt'.eps,replace;
    };
};


***********************************************;
**  spousal income;
************************************************;
infile col t spsinc_bar spsinc_ln_bar sd_spsinc_bar sd_spsinc_ln_bar 
       using ../../bpfcodes_com/data/raw_sipp_spinc.raw, clear;
sort col t;

foreach icol in 0 1 {;
   line spsinc_ln_bar sd_spsinc_ln_bar t `lvcond' & col==`icol', graphregion(color(white)) 
        lpattern("l" "_" "-")  xtitle("Age") `lvxlabel`icol''
        ytitle("Logarithm of spouse income") 
        legend(pos(9) ring(0) col(1) order(1 "ln(inc): mean" 2 "ln(inc): sd"));
   graph export ${gpicsdir}/eps_col`icol'_spinc.eps,replace;
};

cap log close;


